//JavaScript Doccument
var app = Common.initApp(['ngAnimate', 'ui.bootstrap', 'angular.filter']);
Common.initDirective(app);//初始化自定义指令
File.init(app);
app.controller('relevancebusinessController', ['$scope', '$http', 
    function ($scope, $http ) {		
        $scope.relevancebusiness = {};
        $scope.clearrelevanceBusiness = function() {
            $scope.relevancebusiness = {};
        }

        //设置form业务表单信息
        $scope.fillRelevanceBusiness = function(data) {
            if (data) { //设置json格式数据到form表单中
                $scope.relevancebusiness = data;
            }
        };

        //查询渲染填充数据到form表单(用于修改信息前的查询渲染数据)
        if ($scope.XH && $scope.XH != '') {//业务主键不为空,查询填充数据
            Common.send($scope, $http , {
                method : "POST",
                url : Common.webRoot() + '/business/relevance/business/relevancebusinesscontroller/detailData/' + $scope.XH,
                data : {},
                success : function(response) {
                    $scope.fillRelevanceBusiness(response.data.model);//返回查询结果集,渲染填充数据到form表单
                }
            });
        }else{
			$scope.relevancebusiness.XH_TEMP = $scope.XH_TEMP;
		}


        //保存按钮绑定事件方法
        $scope.saveRelevanceBusiness = function() {

            //验证"*"的必须填写，否则无法提交
            if(!Common.validate()) {
                return;
            }

            //添加处理逻辑
            var saveConfig = {
                url : Common.webRoot() + '/business/relevance/business/relevancebusinesscontroller/saveRelevanceBusiness',
                method : 'POST',
                showTips : true,
                data : JSON.stringify($scope.relevancebusiness),
            success : function (response) {
                var data = response.data;
                if (data.model) {
                    $scope.fillRelevanceBusiness(data.model);
                }
            },
            error : function(response) {
                throw new Error('请求[' + saveConfig.url + ']出错,[' + response + ']')
            }
        };
            Common.send($scope, $http, saveConfig);
        };

    }]);
